//
//  YDPeripheral.m
//  IngCard
//
//  Created by kf on 2017/5/26.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDPeripheral.h"

@implementation YDPeripheral

+(instancetype) peripheral:(CBPeripheral*)peripheral
         advertisementData:(NSDictionary*)advertisementData
                      rssi:(NSNumber *)RSSI
{
    YDPeripheral *instance = [[YDPeripheral alloc] init];
 
    instance.peripheral = peripheral;
    instance.advertisementData = advertisementData;
    instance.RSSI = RSSI;
    return instance;
}

#pragma mark - lazy load
-(NSString *)name
{
    if (!_name)
    {
        if ([self.advertisementData objectForKey:@"kCBAdvDataLocalName"]) {
            _name = [NSString stringWithFormat:@"%@",[self.advertisementData objectForKey:@"kCBAdvDataLocalName"]];
        }else if(!([self.peripheral.name isEqualToString:@""] || self.peripheral.name == nil)){
            _name = self.peripheral.name;
        }else{
            _name = [self.peripheral.identifier UUIDString];
        }
    }
    return _name;
}
@end
